package com.m4f.web.controller;


import javax.cache.CacheException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping(value="/error")
public class ErrorController extends BaseController{

	public ErrorController() throws CacheException {
		super();
	}
	
	@RequestMapping(value="/file-format-error", method=RequestMethod.GET)
	public String getError(Model model) {
		String message = this.getMessage("file.uploaded.format.error", null);
		model.addAttribute("message", message);
		return "common/error";
	}
	
	@RequestMapping(value="/404-error", method=RequestMethod.GET)
	public String get404Error(Model model) {
		String message = this.getMessage("page.not.exist", null);
		model.addAttribute("message", message);
		return "common/error";
	}
	
	
	@RequestMapping(value="/upload-error", method=RequestMethod.POST)
	public String uploadingError(Model model, 
			HttpServletRequest request, 
			HttpServletResponse response) {
		String errorCause = request.getAttribute("error-cause")==null? "" : "" 
			+ request.getAttribute("error-cause");
		String message = this.getMessage("error.unknown", null);
		if(errorCause.contains("FileSizeLimitExceededException")) {
			message = this.getMessage("project.summary.upload.size.limit.exceed", null);
		}
		model.addAttribute("message", message);
		return "common/error";
	}
	
	
}